<script type="text/ecmascript-6">
    import Navbar from '../../components/base/navbar.vue';
    import Popup from '../../components/base/mask.vue';
    import PageCancelSuc from '../../projects/dmp/pages/user/cancel_success.vue';
    export default{
      name:"user_register_detail",
      components:{
          Navbar,
          Popup,
          PageCancelSuc
        },
        data(){
            return {
                 myID:this.$route.params.id,
                 showPageCancelSuc:false
            }
        },
        methods:{
          jump_detail() {
               this.$router.push({ name: 'activity_detail', params: {entrance: 'registration', id: this.myID} });
          },
           cancelComplete(){
               this.showPageCancelSuc=true;
           },
           cancelConfirm(){
               this.$Modal.info({title:'消息提示',body:"是否取消报名？",onOk:()=>{
                  this.$store.dispatch('cancelRegister',this.myID);
               }})
           },
           scanner(){
               this.$Modal.info({title:"消息提示",body:"请使用微信扫码进行签到"});
           },
           signComplete(){
               this.$Modal.info({title:"消息提示",body:"签到成功"});
               this.$router.push({name:'gain_coupon',params:{entrance:'user'}});
            }
        },
        created(){
            EventBus.$on("cancel-complete",this.cancelComplete);
            EventBus.$on("sign-complete",this.signComplete);
            this.$store.dispatch("queryRegisterDetail",this.myID);
        },
        beforeDestory(){
          EventBus.$off("cancel-complete");
          EventBus.$off("sign-complete");
        },
        computed:{
          isCanCancel: function () {
            var status = this.detail.data.status,
              mStatus = this.detail.data.member_status,
              start = this.detail.data.starts_at,
              cancel = this.detail.data.refund_term,
              time = new Date(start.replace(/-/g,"/")).getTime() - cancel*60*1000 - new Date().getTime();
            if ( mStatus==1 ) {
              switch (true) {
                case status==1: case status==4: case status==5: case status==2 && time>0:
                return true;
                default:
                  return false;
              }
            }else{
              return false;
            }
          },
          isCanSign: function () {
            const mStatus = this.detail.data.member_status,
              isCan = this.detail.data.can_sign;
            if ( mStatus==1 && isCan===true ) {
              return true;
            }else{
              return false;
            }
          },
            detail:{
                get(){
                    return this.$store.getters.getRegisterDetail
                }
            }
        }
    }
</script>
